import Vue from "vue";
import router from "@/router";
import store from "@/store";
import ProgressBar from "@/components/ProgressBar";

const bar = (Vue.prototype.$bar = new Vue(ProgressBar).$mount());
document.body.appendChild(bar.$el);

router.beforeEach((to, form, next) => {
  // 针对微信分享出来打不开的问题
  let href = window.location.href;
  if (
    href.indexOf("groupmessage") > -1 ||
    href.indexOf("singlemessage") > -1 ||
    href.indexOf("timeline") > -1
  ) {
    href = href
      .replace(/\?from=(groupmessage|singlemessage|timeline)(\S*)#/, "#")
      .replace(/\?scene=(\S*)#/, "#");
    window.location.href = href;
  }

  if (to.query.ismaster) {
    return
  }

  let panoId = to.params.panoId;
  let ovvId = to.query.ovv;

  // 全景
  if (to.name === "Home") {
    if(!to.query.scene_id || !store.getters.panoId)
      store.dispatch("initData", { panoId: panoId, ovvId: ovvId });
  }
  // Overview总览图 Tourview旅游导览图
  if (to.name === "Overview" || to.name === "Tourview") {
    store.dispatch("fetchOverview", to.params.id);
    bar.start();
  }
  // 手绘图
  if (to.name === "Handdraw") {
    store.dispatch("fetchHanddraw", to.params.id);
  }
  // if (to.name === "AerialPhotography") {
  //   store.dispatch("clearAppInfo")
  //   store.dispatch("initAearialData", {panoId: panoId});
  // }
  // if (to.name === "Works") {
  //   bar.start();
  // }
  // if (to.name === "Goods") {
  //   bar.start();
  // }
  next();
});
